# 占位符
print('%.2f' % 3.1415)
print("%3d" % 32)


######################################## 函数参数


# 位置参数
def position_param(param):
    print("param=%s" % param)


position_param('haha')


# 默认参数
def default_param(param, p='default'):
    print('param=%s, p=%s' % (param, p))


default_param('meituan', 'toutiao')


# 可变参数
def flex_param(param, *args):
    print('param=%s' % param, ', args type is {0}'.format(type(args)), args)


flex_param('first', ['a', 'b'])
list_param = ['a', 'b']
flex_param('first', *list_param)
flex_param('first', ('a', 'b',))


# 关键字参数
def key_param(param, **kw):
    print('param=%s' % param, 'kw type is {0}'.format(type(kw)))
    for k in kw:
        print('k={0}, w={1}'.format(k, kw.get(k)))


dict_param = {'one': 1, 'two': 2}
key_param('不能直接将dict传入，需要通过**拆包后传入', **dict_param)
key_param('key=value方式传入', one='wang', two='tu')


# 命名关键字参数
def key_name1_param(param, *, param1, param2):
    print('param1={0}, param2={1}'.format(param1, param2))


def key_name2_param(param, *args, param1, param2):
    print('args={0}, param1={1}, param2={2}'.format(args, param1, param2))


key_name1_param('first', param1='1', param2='2')
ps = ['a', 'b']
key_name2_param('second', *ps, param1='1', param2='2')


# 各种类型的参数组合
def amazing_param(*args, **kw):
    print('可以表示所有的参数类型, args={0}, kw={1}'.format(args, kw))


ap = ['a', 'b', 'c']
bp = {'a': 1, 'b': 2}
amazing_param(ap, 'over', **bp)


